﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Drawing;
using CGLib;

namespace TienLen
{
    /// <summary>
    /// Contains and holds the images of cards.
    /// </summary>
    class CardSkins
    {
        #region Fields

        private Dictionary<int, string> skins = new Dictionary<int, string>();
        private string skinuse = string.Empty;

        private string[] cards = new string[52];

        #endregion

        #region Properties

        /// <summary>
        /// The directory of the current used skin.
        /// </summary>
        public string SelectedSkinDirectory
        {
            get { return skinuse; }
        }

        #endregion


        public CardSkins()
        {
            StreamReader skincfg = new StreamReader(Application.StartupPath + @"\config\skins.cfg");

            do { skins.Add(0, skincfg.ReadLine()); }
            while (skincfg.EndOfStream == false);

            skinuse = Application.StartupPath + @"\img\skins\" + skins[TienLen.Properties.Settings.Default.defskin] + "\\";

            LoadCards();
        }

        /// <summary>
        /// Returns the complete location of the cards image location.
        /// </summary>
        /// <returns></returns>
        public string GetCardPath(Card card)
        {
            return skinuse + cards[13 * ((int)card.Suite - 1) + (int)card.Value - 1];
        }

        /// <summary>
        /// Add a list of card filenames in ranking order.
        /// </summary>
        private void LoadCards()
        {     
            // Spades
            cards[0] =  "spade\\A.png";
            cards[1] =  "spade\\2.png";
            cards[2] =  "spade\\3.png";
            cards[3] =  "spade\\4.png";
            cards[4] =  "spade\\5.png";
            cards[5] =  "spade\\6.png";
            cards[6] =  "spade\\7.png";
            cards[7] =  "spade\\8.png";
            cards[8] =  "spade\\9.png";
            cards[9] =  "spade\\10.png";
            cards[10] =  "spade\\J.png";
            cards[11] =  "spade\\Q.png";
            cards[12] =  "spade\\K.png";

            // Clubs
            cards[13] =  "club\\A.png";
            cards[14] =  "club\\2.png";
            cards[15] =  "club\\3.png";
            cards[16] =  "club\\4.png";
            cards[17] =  "club\\5.png";
            cards[18] =  "club\\6.png";
            cards[19] =  "club\\7.png";
            cards[20] =  "club\\8.png";
            cards[21] =  "club\\9.png";
            cards[22] =  "club\\10.png";
            cards[23] =  "club\\J.png";
            cards[24] =  "club\\Q.png";
            cards[25] =  "club\\K.png";

            // Diamond
            cards[26] =  "diamond\\A.png";
            cards[27] =  "diamond\\2.png";
            cards[28] =  "diamond\\3.png";
            cards[29] =  "diamond\\4.png";
            cards[30] =  "diamond\\5.png";
            cards[31] =  "diamond\\6.png";
            cards[32] =  "diamond\\7.png";
            cards[33] =  "diamond\\8.png";
            cards[34] =  "diamond\\9.png";
            cards[35] =  "diamond\\10.png";
            cards[36] =  "diamond\\J.png";
            cards[37] =  "diamond\\Q.png";
            cards[38] =  "diamond\\K.png";

            // Hearts
            cards[39] =  "heart\\A.png";
            cards[40] =  "heart\\2.png";
            cards[41] =  "heart\\3.png";
            cards[42] =  "heart\\4.png";
            cards[43] =  "heart\\5.png";
            cards[44] =  "heart\\6.png";
            cards[45] =  "heart\\7.png";
            cards[46] =  "heart\\8.png";
            cards[47] =  "heart\\9.png";
            cards[48] =  "heart\\10.png";
            cards[49] =  "heart\\J.png";
            cards[50] =  "heart\\Q.png";
            cards[51] =  "heart\\K.png";
        }
    }
}
